<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
        	<form class="form-horizontal m" id="form-daily-edit" th:object="${daily}">
           		 <input id="dailyId" name="dailyId" th:field="*{dailyId}"  type="hidden">
				<input name="userId"  type="hidden" id="chooseId" th:field="*{userId}"/>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作内容：</label>
					<div class="col-sm-8">
						<textarea id="workContent" name="workContent" class="form-control" style="height: 100px;">[[*{workContent}]]</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作时间：</label>
					<div class="col-sm-3">
						<input id="commonDate" name="workDate" th:field="*{workDate}" class="form-control" type="text" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作时长：</label>
					<div class="col-sm-3">
						<input id="workHours" name="workHours" th:field="*{workHours}" class="form-control" type="number">
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">审批人：</label>
					<div class="col-sm-3">
						<input class="form-control" type="text" name="userName" onclick="chooseUser()" readonly="true" id="chooseName" th:field="*{user.userName}">
					</div>
				</div>
				<!--<div class="form-group">-->
					<!--<label class="col-sm-3 control-label">是否加班：</label>-->
					<!--<div class="col-sm-8">-->
						<!--<div class="onoffswitch">-->
							<!--<input type="checkbox" th:checked="${daily.workOvertime == '1' ? true : false}" onclick="overtime(this)" class="onoffswitch-checkbox" id="workOvertime" name="workOvertime">-->
							<!--<label class="onoffswitch-label" for="workOvertime">-->
								<!--<span class="onoffswitch-inner"></span>-->
								<!--<span class="onoffswitch-switch"></span>-->
							<!--</label>-->
						<!--</div>-->
					<!--</div>-->
				<!--</div>-->
				<!--<div class="form-group">-->
					<!--<label class="col-sm-3 control-label">加班内容：</label>-->
					<!--<div class="col-sm-8">-->
						<!--<textarea id="overtimeContent" name="overtimeContent" class="form-control" style="height: 100px;" disabled>[[*{overtimeContent}]]</textarea>-->
					<!--</div>-->
				<!--</div>-->
				<!--<div class="form-group">-->
					<!--<label class="col-sm-3 control-label">加班时长：</label>-->
					<!--<div class="col-sm-3">-->
						<!--<input id="overtimeHours" name="overtimeHours" th:field="*{overtimeHours}" class="form-control" type="number" disabled>-->
					<!--</div>-->
				<!--</div>-->
				<div class="form-group">
					<label class="col-sm-3 control-label">备注：</label>
					<div class="col-sm-8">
						<textarea id="remark" name="remark" class="form-control" style="height: 100px;">[[*{remark}]]</textarea>
					</div>
				</div>
				<div class="form-group">
					<div class="form-control-static col-sm-offset-9">
						<button type="submit" class="btn btn-primary">提交</button>
						<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
					</div>
				</div>
			</form>
		</div>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
        $(document).ready(function(){
            var overtimeFlag= $("input[name='workOvertime']").is(':checked');
            changeStatus(overtimeFlag);
        });
        function overtime(obj) {
            changeStatus(obj.checked);
        }

        function changeStatus(flag) {
            if(flag){
                $("#overtimeContent").attr("disabled",false);
                $("input[name='overtimeHours']").prop("disabled",false);
            }else{
                $("#overtimeContent").attr("disabled",true);
                $("input[name='overtimeHours']").prop("disabled",true);
                $("#overtimeContent").val("");
                $("input[name='overtimeHours']").val("");
            }
        }

		var prefix = ctx + "module/daily"
		$("#form-daily-edit").validate({
			rules:{
                workContent:{
                    required:true,
                    minlength: 5,
                    maxlength: 500
                },
                workDate :{
                    required:true
                },
                workHours :{
                    required:true,
                    maxlength: 20
                },
                // overtimeContent:{
                //     required:true,
                //     maxlength: 500
                // },
                // overtimeHours :{
                //     required:true,
                //     maxlength: 20
                // }
			},
			submitHandler: function(form) {
				// $.operate.save(prefix + "/edit", $('#form-daily-edit').serialize());
				edit();
			}
		});
		function edit() {
            var dailyId = $("input[name='dailyId']").val();
            var workContent = $("#workContent").val();
            var workDate = $("input[name='workDate']").val();
            var workHours = $("input[name='workHours']").val();
            var userId = $("input[name='userId']").val();
            // var workOvertime = $("input[name='workOvertime']").is(':checked') == true ? 1 : 0;
            // var overtimeContent = $("#overtimeContent").val();
            // var overtimeHours = $("input[name='overtimeHours']").val();
            var remark = $("#remark").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/edit",
                data : {
                    "dailyId" :dailyId,
                    "workContent": workContent,
                    "workDate": workDate,
                    "workHours": workHours,
					"userId":userId,
                    // "workOvertime": workOvertime,
                    // "overtimeContent": overtimeContent,
                    // "overtimeHours": overtimeHours,
                    "remark":remark
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

        function chooseUser() {
            var url = ctx + "system/user/chooseUser/";
            $.modal.open("选择审批人", url, '600', '380');
        }

	</script>
</body>
</html>
